import { getDictListList, getDictList, delDictList, saveDictList, updateDictList } from '@/api/sys/dictList'

const actions = {
  // 获取字典列表
  getDictListList({ commit }, param) {
    return new Promise((resolve, reject) => {
      getDictListList(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**只是获取一条数据 */
  getDictList({ commit }, id) {
    return new Promise((resolve, reject) => {
      getDictList(id).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  updateDictList({ commit }, param) {
    return new Promise((resolve, reject) => {
      updateDictList(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   * 保存字典
   * @param {字典} data
   */
  saveDictList({ commit }, param) {
    return new Promise((resolve, reject) => {
      saveDictList(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   *  删除字典 list
   * @param {id} id
   */
  delDictList({ commit }, id) {
    return new Promise((resolve, reject) => {
      delDictList(id).then(res => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }

}

export default {
  namespaced: true,
  actions
}
